<template>
	<view>
		<view class="list">
			<block v-for="(item,index) in list" :key="index">
				<view class="orderDetail">
					<view class="top">					
						<text class="order_no">订单号：{{item.order_no}}</text>
					</view>
					<view class="goodsinfo">
						<view class="m-img" :style="'background:url('+item.goods.img+')no-repeat;background-size:cover;'">
						</view>
						<view class="m-text">
							<view class="m-title">
								{{item.goods.name}}
							</view>
							<view class="m-descripe">
								<text v-if="item.goods.des">{{item.goods.des}}</text>
							</view>
							<view class="m-price">
								￥{{item.price}} * {{item.number}}
								<text style="margin-left: 10rpx;" class="tag-danger" v-if="item.refuse_number">退{{item.refuse_number}}{{item.spec.unit}}</text>
							</view>
						</view>
					</view>					
					<view class="footer">
						<view class="zhifu">
							<text>下单日期：{{item.createtime}}</text>
							<text>{{item | parsePay}}</text>
						</view>
					</view>
				</view>
			</block>	
			<view v-if="list.length==0">
				<u-empty text="没有订单!" mode="search" marginTop="150"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import {methods} from '@/utils/methods.js';
	export default {
		data() {
			return {
				customer:'',
				endData:false,
				page:1,
				list:[],		
			}
		},
		onLoad() {
			this.customer=this.$customer();
			if(!this.customer){
				this.$reLaunch('index/index');
				return;
			}
			this.init();
		},
		onReachBottom() {
			this.pagelist();
		},
		onPullDownRefresh() {
			this.init(true);
		},
		filters:{
			parsePay:function(item){
				let r='支付：';
				if(item.total_money>0){
					r+='￥'+item.total_money;
				}
				if(item.total_score){
					if(item.total_money>0){
						r+=' + ';
					}
					r+=item.total_score+'积分';
				}
				return r;
			}
		},
		methods: {
			...methods,
			init:function(pulldown){
				this.page=1;
				this.endData=false;
				this.list=[];
				this.pagelist(pulldown);
			},
			pagelist:function(pulldown=false){
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get("shop/orderlist",{
					customer_id:this.customer.id,
					page:this.page
				},true).then(res=>{
					if(pulldown){
						uni.stopPullDownRefresh();
					}
					if(res.length<10){
						this.endData=true;
					}
					this.list=this.list.concat(res);	
					this.page++;	
				});		
			}
		}
	}
</script>

<style lang="scss">
.list{
	padding: 20rpx;
	font-size: 24rpx;
	.orderDetail{
		min-height: 100rpx;
		margin-bottom: 20rpx;
		border-radius: 6rpx;
		box-shadow: 0rpx 0rpx 20rpx #bebebe;
		padding: 20rpx;
		.top{
			display: flex;
			justify-content: space-between;
		}
		.footer{
			text-align: left;
			margin-top: 20rpx;
			.zhifu{
				display: flex;
				justify-content: space-between;
				margin-top: 10rpx;
			}
		}
		.btn-group{
			margin-top: 20rpx;
			display: flex;
			justify-content: flex-end;
			margin-left: 80%;
			width: 20%;			
		}
		.goodsinfo{
			display: flex;
			flex-direction: row;
			width: 100%;
			justify-content: space-between;
			align-items: flex-end;
			margin-top: 20rpx;
			background-color: #f7f7f7;
			padding:10rpx 0;
			.m-img{
				height: 190upx;
				width: 210upx;
				border-radius: 10upx;
				margin-left: 10rpx;
			}
			.m-text{
				flex:1;
				padding: 0 20upx;
				.m-title{
					font-size: 32upx;
					color:#4c4c4c;
					margin-bottom: 20upx;
				}
				.m-descripe{
					font-size: 24upx;
					color:#999999;
					display: flex;
					justify-content: space-between;
					margin-bottom: 20upx;
				}
				.m-price{
					font-size: 28upx;
					color:#ff582b;
					font-weight: bold;
				}
			}
		}
	}
}
</style>
